<!-- BEGIN PAGE HEADER-->
<?php $this->load->view('partials/breadcrumb.tpl') ?>
<style>
    th,td{
        text-align: center;
    }
    .o-img{
        width: 50px !important;
        height: auto !important;
        border-radius: 50%;
    }
    .o-name{
        margin-left: 5px;
    }
</style>
<script type="text/javascript">
    function defConfirm() {
        if (!confirm("确认车辆已归还吗？")) {
            return false;
        }
        return true;
    }

    $(document).ready(function () {
        $("#reset").click(function () {
            $("select").val('');
            $("input[type='text']").val('');
        });
    });
</script>
<div class="row">
    <div class="col-xs-12">
        <!-- Begin: life time stats -->
        <div class="portlet">
            <?= form_open('', Array('class' => 'form-inline', 'role' => 'form')) ?>
            <?= search_form_input('order_no', filterValue('order_no'), '订单号', 'class="form-control input-small"'); ?>
            <?= search_form_input('out_trade_no', filterValue('out_trade_no'), '支付订单号', 'class="form-control input-small"'); ?>
            <?= search_form_input('name', filterValue('name'), '车辆名称', 'class="form-control input-small"'); ?>
            <?= search_form_input('brand', filterValue('brand'), '车辆品牌', 'class="form-control input-small"'); ?>
            <?= search_form_dropdown('user_id', array('' => '选择用户...') + $allUser, filterValue('user_id'), '用户', 'class="form-control input-xs select2me"'); ?>
            <?= search_form_dropdown('status', array('' => '选择订单状态...') + IOSS_StaticConfig::getOrderType(), filterValue('status'), '订单状态', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('pay_status', array('' => '选择支付状态...') + [ 0 => '未支付', 1 => '已支付'], filterValue('pay_status'), '支付状态', 'class="form-control input-xs"'); ?>
            <div style="clear:both;height:14px;"></div>
            <?= search_form_input('order_number_perpage', filterValue('order_number_perpage'), '每页显示条数', 'class="form-control input-small"'); ?>
            <div class="input-group input-large date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">
                <input type="text" class="form-control" name="order_time_begin"
                       value="<?= filterValue('order_time_begin') ?>" placeholder="订单起始时间" autoComplete="off">
                <span class="input-group-addon">to </span>
                <input type="text" class="form-control" name="order_time_end"
                       value="<?= filterValue('order_time_end') ?>" placeholder="订单结束时间" autoComplete="off">
            </div>
            <button type="button" class="btn default" id="reset">重置条件</button>
            <button type="submit" class="btn green about_search">搜索 <i class="fa fa-search"></i></button>
            <?= form_close() ?>
            <div class="portlet-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-scrollable">
                            <table class="table table-hover table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>订单编号</th>
                                    <th>支付订单号</th>
                                    <th>用户</th>
                                    <th>车辆</th>
                                    <th>订单总额</th>
                                    <th>还车时间</th>
                                    <th>支付状态</th>
                                    <th>支付时间</th>
                                    <th>订单状态</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($list as $v) { ?>
                                    <tr>
                                        <td><?= $v->id ?></td>
                                        <td><?= $v->order_no ?></td>
                                        <td><?= $v->out_trade_no ?></td>
                                        <td>
                                            <img class="o-img img-rounded" src="<?= $v->avatar ?>" alt="<?= $v->nick_name ?>">
                                            <span class="o-name"><?= $v->nick_name ?></span>
                                        </td>
                                        <td>
                                            <img class="o-img img-rounded" src="<?= image_url($v->picture) ?>" alt="<?= $v->name ?>">
                                            <span class="o-name"><?= $v->name ?></span>
                                        </td>
                                        <td><?= $v->amount > 0?'￥'.$v->amount:'<label class="label label-danger">使用中</label>' ?></td>
                                        <td><?= $v->return_time?date('Y-m-d H:i:s', $v->return_time):'<label class="label label-warning">未还车</label>' ?></td>
                                        <td>
                                            <?= $v->pay_status?'<label class="label label-success">已支付</label>':'<label class="label label-danger">未支付</label>' ?>
                                        </td>
                                        <td>
                                            <?= $v->pay_time?date('Y-m-d H:i:s', $v->pay_time):'<label class="label label-primary">未支付</label>' ?>
                                        </td>
                                        <td><?= IOSS_StaticConfig::getOrderType($v->status) ?></td>
                                        <td><?= date('Y-m-d H:i:s', $v->create_time) ?></td>
                                        <td>
                                            <div class="btn-group btn-group-solid">
                                                <a href="javascript:ioss_url_modal('<?= site_url('/order/order/ajaxViewDetail/' . $v->id) ?>');" class="btn btn-sm blue"><i class="fa fa-play"></i> 查看</a>
                                                <?php if ($v->status == 1): ?>
                                                <a href="javascript:;" data-oid="<?= $v->id ?>" class="btn btn-sm purple confirm-return"><i class="fa fa-edit"></i> 确认还车</a>
                                                <?php endif; ?>
                                            </div>
                                        </td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right">
                        <?= $pagination ?>
                    </div>
                </div>
            </div>
        </div>
        <!-- End: life time stats -->
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('.img-rounded').zoomify();
    });
    $(".confirm-return").click(function () {
        var oid = this.dataset.oid;
        if (defConfirm()){
            $.ajax({
                url: "<?= site_url('order/order/return_confirm') ?>",
                method: "POST",
                data: {'oid': oid},
                dataType: "JSON",
                success: function (data) {
                    if (data.status){
                        toastr.success(data.msg,'成功');
                        setTimeout(function () {
                            location.reload()
                        },1000)
                    }else {
                        toastr.error(data.msg,'失败');
                    }
                }
            })
        }
    })
</script>
